//
//  Players.m
//  TabulaImaginarius
//
//  Created by TA2 on 4/2/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Players.h"


@implementation Players

static Players *players = nil;
static Player *player = nil;
static NSMutableArray *sharedBonjourPlayers = nil;

+ (Players *)sharedPlayers {
    if (players == nil) {
        players = [[NSMutableArray allocWithZone:NULL] init];
    }
    return players;
}

+ (Player *) sharedLocalPlayer {
	if (player == nil) {
        player = [[[Player alloc] init] retain];
    }
    return player;
}
+ (NSMutableArray *) sharedAllPlayers {
	NSMutableArray *allPlayers = [NSMutableArray arrayWithArray:[Players sharedPlayers]];
	[allPlayers addObject:[Players sharedLocalPlayer]];
	return allPlayers;
}
+ (NSMutableArray *)sharedBonjourPlayers {
    if (sharedBonjourPlayers == nil) {
        sharedBonjourPlayers = [[NSMutableArray allocWithZone:NULL] init];
    }
    return sharedBonjourPlayers;
}
+ (Player *) playerWithIp:(NSString *) ip {
	for (Player *player in [self sharedAllPlayers]) {
		if ([player.ip isEqualToString:ip]) {
			return player;
		}
	}
	return nil;
}

+ (id)allocWithZone:(NSZone *)zone {
    return [[self sharedPlayers] retain];
}

- (id)copyWithZone:(NSZone *)zone {
    return self;
}

- (id)retain {
    return self;
}

- (NSUInteger)retainCount {
    return NSUIntegerMax;  //denotes an object that cannot be released
}

- (void)release {
    //do nothing
}

- (id)autorelease {
    return self;
}

@end

